package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Feedback;
import com.restaurant.service.FeedbackService;

public class FeedbackServiceImpl implements FeedbackService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Feedback addOrModify( Feedback objFeedback ) {
       return ( Feedback ) hibernateTemplate.merge( objFeedback );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Feedback deleteRecord( Feedback objFeedback ) {
       hibernateTemplate.delete( objFeedback );
       return objFeedback;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Feedback modifyRecord( Feedback objFeedback ) {
       return ( Feedback ) hibernateTemplate.merge( objFeedback );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Feedback> loadAll() {
       return (List<Feedback>)hibernateTemplate.findByNamedQuery( "Feedback.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Feedback loadByPrimaryKey( Long primaryKey ) {
       return (Feedback) hibernateTemplate.get( Feedback.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Feedback deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Feedback> loadByHql(String query) {
       return ( List<Feedback> ) hibernateTemplate.find( query );
   }
}